<template>
	<view class="bankContent">
		<view class="bankWrap">
			<view class="bankTop" v-for="(item,index) in cardList" :key="item.id">
				<view class="bankTopMessage">
					<text>{{item.bankName}}</text>
					<text>{{item.bankCardNo|cardMessage}}</text>
				</view>
			</view>
			<view class="bankBtns" @click="cancelBankcard()">
				<text>解绑</text>
			</view>
		</view>
		<view class="mask" v-if="isShowMask">
			<view class="waive-pouple">
				<view class="pouple-box">
					<view class="bankCentercontent">
						<view class="popup-boxImage">
							<image src="../../static/image/bankImg.png"></image>
						</view>
						<view class="popup-boxText bankTexts">
							<text>请确认是否解绑</text>
						</view>
					</view>
					<view class="pouple-bottomFlex">
						<view class="flexFir" @click="waiveCofirm">
							取消
						</view>
						<view class="flexSec" @click="againThink(cardList[0].id)">
							确认
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import api from '../../api/index.js'
	export default {
		data() {
			return {
				isShowMask: false,
				cardList: [], //银行卡列表
			}
		},
		onLoad() {
			this.getBankList()
		},
		// 页面销毁
		onUnload: function() {
			console.log('页面销毁')
			var that = this
			let pages = getCurrentPages()
			//判断页面栈里面的页面数是否大于2
			if (getCurrentPages().length > 2) {
				//获取页面栈
				let pages = getCurrentPages()
				//给上一个页面设置状态
				let curPage = pages.length - 2;
				uni.navigateBack({
					delta: curPage
				})
			}
		},
		methods: {

			//  绑定银行卡
			cancelBankcard() {
				this.isShowMask = true;
			},
			//取消按钮
			waiveCofirm() {
				this.isShowMask = false;
			},
			// 获取银行卡列表
			getBankList() {
				api.myHelp.bankList().then(res => {
					if (res.code == 1) {
						this.cardList = res.data;
					}
				})
			},
			// 解绑银行卡
			againThink(id) {
				api.myHelp.UntyingBank(id).then(res => {
					if (res.code == 1) {
						this.isShowMask = false;
						uni.showToast({
							title: '解绑成功'
						})
						uni.navigateBack()
					}
				})
			}
		}
	}
</script>

<style>
	@import "../../static/css/common.css";
	@import url("./bindBank.css");
</style>
